package com.ganee.agora.adapter

import android.graphics.Bitmap
import android.provider.MediaStore
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ganee.agora.R
import com.ganee.agora.manager.RecyclerViewHolder
import com.ganee.agora.manager.RoundedCornersTransform
import com.ganee.agora.model.ChooseGalleryEntity
import com.ganee.agora.model.ChooseLocalEntity
import com.ganee.agora.model.FileEntity
import com.ganee.agora.model.InsertActivityEntity
import com.ganee.agora.utils.ImgUtils
import com.ganee.agora.widget.ratingbar.AndRatingBar
import com.ganee.baselib.mvvmlibrary.widget.loadingdrawable.DensityUtil
import com.ganee.baselib.widget.image.transform.GlideRoundTransform
import com.luck.picture.lib.entity.LocalMedia


/**
 *    @author : EricCui
 *    date   : 2020-01-01 17:52
 *    desc   :  your event adapter
 */

class PostEventChooseAdapter(entityList: MutableList<FileEntity>) : BaseQuickAdapter<FileEntity,
        RecyclerViewHolder>(R.layout.item_recyclerview_choose_album, entityList) {

    override fun convert(helper: RecyclerViewHolder, item: FileEntity) {
        val ivDelete = helper.getView<ImageView>(R.id.choose_iv_delete) as ImageView
        val ivPic = helper.getView<ImageView>(R.id.choose_iv_pic) as ImageView
        val ivPlay = helper.getView<ImageView>(R.id.choose_iv_play) as ImageView
        val transform = RoundedCornersTransform(mContext, DensityUtil.dip2px(mContext, 10F))
        transform.setNeedCorner(true, true, true, true)
        if (item != null) {
            if ("01" == item.fileType){
                ivDelete.visibility = View.VISIBLE
                Glide.with(mContext)
                        .load(item.filePath)
                        .transform(transform)
                        .into(ivPic)
                ivPlay.visibility = View.GONE
            } else if ("02" == item.fileType){
                ivDelete.visibility = View.VISIBLE
//                val bitmap = ImgUtils.createVideoThumbnail(item.filePath, MediaStore.Images.Thumbnails.MINI_KIND) as Bitmap
//                ivPic.setImageBitmap(bitmap)
                ivPlay.visibility = View.VISIBLE
            } else {
                ivPlay.visibility = View.GONE
                ivDelete.visibility = View.GONE
                ivPic.setImageResource(R.drawable.post_event_add)
            }
        }
        helper.addOnClickListener(R.id.choose_iv_delete)
    }
}